package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.system.entity.XcxAdvert;
import com.ibiaoke.system.service.XcxAdverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Dragon
 * @date 2018/4/3/10:03;
 */
@Controller
public class BossXcxAdverController extends BaseController {
    @Autowired
    private XcxAdverService xcxAdverService;

    /**
     * 添加Advert
     *
     * @param advert
     * @return
     */
    @ResponseBody
    @RequestMapping("saveXcxAdvert")
    public Res saveAdvert(@Valid XcxAdvert advert, BindingResult result) {
        handleValidate(result);
        xcxAdverService.saveAdvert(advert);
        return Res.create();
    }

    /**
     * 修改Advert
     *
     * @param advert
     * @return
     */
    @ResponseBody
    @RequestMapping("updateXcxAdvertById")
    public Res updateAdvertById(XcxAdvert advert) {
        xcxAdverService.updateBannerById(advert);
        return Res.create();

    }

    /**
     * 删除Advert
     *
     * @param advertId
     * @return
     */
    @ResponseBody
    @RequestMapping("deleteXcxAdvertById")
    public Res deleteAdvertById(Integer advertId) {
        xcxAdverService.deleteBannerById(advertId);
        return  Res.create();
    }

    /**
     * 批量删除Advert
     *
     * @param xcxAdvertIds
     * @return
     */
    @ResponseBody
    @RequestMapping("batchDeleteXcxAdver")
    public Res batchDeleteXcxAdver(String xcxAdvertIds) {
        xcxAdverService.batchDeleteXcxAdver(xcxAdvertIds);
        return  Res.create();
    }

    /**
     * 查询Advert
     *
     * @param xcxAdvert
     * @return
     */
    @ResponseBody
    @RequestMapping("listXcxAdvert")
    public Res listAdvert(XcxAdvert xcxAdvert,Page page) {
        List<XcxAdvert> advertList = xcxAdverService.listBanner(xcxAdvert,page);
        return Res.create().addResponse("advertList", advertList).addResponse("page",page);
    }
}
